package com.wnhz.work.yz.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

import org.xutils.ex.HttpException;


/**
 * Created by d on 2017/1/13.
 */

public class MyException {

    public static void onExceptionToast(Context context, HttpException error, String msg) {

        if (msg.indexOf("ConnectTimeoutException") > 0) {
            Toast.makeText(context, "网络不给力", Toast.LENGTH_SHORT).show();
        } else {
            if (isNetworkConnected(context)){

            }else {
                Toast.makeText(context, "网络已断开，请检查网络", Toast.LENGTH_SHORT).show();
            }
        }
    }

    public static boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }
}
